// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.Resources;
using System.Web.Script;
using AjaxControlToolkit;
using System.Drawing;

[assembly: System.Web.UI.WebResource("GridControl.calendar.CalendarExtenderBehavior.js", "text/javascript")]
namespace GridControl
{ 
    /// <summary>
    /// Class to extend a TextBox into a calendar popup
    /// </summary>
    [Designer("GridControl.GridControlDesigner, GridControl")]
    [ClientScriptResource("GridControl.CalendarExtenderBehavior", "GridControl.calendar.CalendarExtenderBehavior.js")]
    [TargetControlType(typeof(TextBox))]
    [RequiredScript(typeof(YUI), 1)]
    [RequiredScript(typeof(ext_yui_adapter), 2)]
    [RequiredScript(typeof(YUI_ext), 3)]
    [RequiredScript(typeof(GridExtenstions), 4)]
    [ToolboxBitmap(typeof(System.Web.UI.WebControls.Calendar))]
    public class CalendarExtender : ExtenderControlBase
    {   
        /// <summary>
        /// An array of days to disable, 0 based. For example, [0, 6] disables 
        /// Sunday and Saturday (defaults to null).
        /// </summary>
        [ExtenderControlProperty]
        public string disabledDays
        {
            get
            {
                return GetPropertyValue<string>("disabledDays", null);
            }
            set
            {
                SetPropertyValue<string>("disabledDays", value);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public string disabledDaysText
        {
            get
            {
                return GetPropertyValue<string>("disabledDaysText", null);
            }
            set
            {
                SetPropertyValue<string>("disabledDaysText", value);
            }
        }
        /// <summary>
        /// An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular expression so they are very powerful.
        /// Some examples:  * ["03/08/2003", "09/16/2003"] would disable those exact dates
       /// * ["03/08", "09/16"] would disable those days for every year
       ///* ["^03/08"] would only match the beginning (useful if you are using short years)
        ///* ["03/../2006"] would disable every day in March 2006
       ///* ["^03"] would disable every day in every March
       ///In order to support regular expressions, if you are using a date format that has "." in it, you will have to escape the dot when restricting dates. For example: ["03\\.08\\.03"].
        /// </summary>
        [ExtenderControlProperty]
        public string disabledDates
        {
            get
            {
                return GetPropertyValue<string>("disabledDates", string.Empty);
            }
            set
            {
                SetPropertyValue<string>("disabledDates", value);
            }
        }
        /// <summary>
        ///  The tooltip text to display when the date falls on a
        /// disabled date (defaults to 'Disabled')
        /// </summary>
        [ExtenderControlProperty]
        public string disabledDatesText
        {
            get
            {
                return GetPropertyValue<string>("disabledDatesText", string.Empty);
            }
            set
            {
                SetPropertyValue<string>("disabledDatesText", value);
            }
        }
        
        /// <summary>
        /// The default date format string which can be overriden for localization support. 
        /// The format must be valid according to Date.parseDate (defaults to 'm/d/y').
        /// </summary>
        [ExtenderControlProperty]
        public string format
        {
            get
            {
                return GetPropertyValue<string>("format", string.Empty);
            }
            set
            {
                SetPropertyValue<string>("format", value);
            }
        }

        /// <summary>
        /// Raises the pre render event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            string resource = Page.ClientScript.GetWebResourceUrl(GetType(), "GridControl.yui-ext.css");
            string csslink = "<link href='" + resource + "' rel='stylesheet' type='text/css' />";
            Page.Header.Controls.Add(new LiteralControl(csslink));

           
        }
    }
}